package cn.midas.basic.controller;

import cn.midas.basic.service.IGraphCodeService;
import cn.midas.basic.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/graphCode")
public class GraphCodeController {

    @Autowired
    private IGraphCodeService graphCodeService;

    @GetMapping ("/image/{imageCodeKey}") // 请求地址：http://localhost:8080/department/1 GET请求
    public AjaxResult graph(@PathVariable("imageCodeKey") String imageCodeKey){
        try {
            String base64Str = graphCodeService.graph(imageCodeKey);
            return AjaxResult.me().setResultObj(base64Str);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }
}
